package com.obrempon.credit.market.ui.adapter

import androidx.recyclerview.widget.RecyclerView
import com.obrempon.credit.market.R
import com.obrempon.module.adapter.ObremponRecyclerViewAdapter
import com.obrempon.module.adapter.ObremponViewHolderHelper
import com.obrempon.module.shapeview.layout.ShapeLinearLayout
import org.json.JSONObject

/**
 * ObremponCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/19 13:54
 * @Annotation：认证流程 - 性别选择
 */
class ObremponAuthStepGenderItemApt(recyclerView: RecyclerView?) :
    ObremponRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.obrempon_auth_step_common_gender_child_item) {
    override fun setItemChildListener(helper: ObremponViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.genderItemLayout)//选择
    }

    override fun fillData(helper: ObremponViewHolderHelper, position: Int, model: JSONObject) {
        val genderItemLayout = helper.getView<ShapeLinearLayout>(R.id.genderItemLayout)
        val imgGenderType = helper.getImageView(R.id.imgGenderType)
        val textGenderTitle = helper.getTextView(R.id.textGenderTitle)
        val imgGenderSelector = helper.getImageView(R.id.imgGenderSelector)
        imgGenderType.setImageResource(model.optInt("genderIcon"))
        textGenderTitle.text = model.optString("title")

        if (model.optBoolean("isSelected", false)) {
            genderItemLayout.shapeDrawableBuilder
                .setStrokeColor(getColor(R.color.color_ff0569ff))
                .setStrokeSize(mContext.resources.getDimension(com.obrempon.module.R.dimen.dp_1).toInt())
                .intoBackground()
            imgGenderSelector.setImageResource(R.mipmap.obrempon_gender_selected_icon)
        } else {
            genderItemLayout.shapeDrawableBuilder
                .setStrokeColor(getColor(R.color.color_ffeceff3))
                .setStrokeSize(mContext.resources.getDimension(com.obrempon.module.R.dimen.dp_1).toInt())
                .intoBackground()
            imgGenderSelector.setImageResource(R.mipmap.obrempon_gender_normal_icon)
        }
    }
}